﻿#include "../Inc/disp_comm.h"
#include "../Inc/data_public.h"

typedef struct Label_t
{
	char* label_cont;				// 标签内容
	lv_coord_t width;				// 标签宽度
	lv_coord_t height;				// 标签高度
	lv_color_t color;				// 标签颜色
	lv_coord_t pos_x;				// 标签x坐标
	lv_coord_t pos_y;				// 标签y坐标
}Label_t;
typedef struct Roller_t
{
	uint8_t id;					    // 滚轮ID
	uint8_t row_cnt;			    // 滚轮显示的选项行数
	lv_coord_t width;			    // 滚轮的宽度
	lv_coord_t pos_x;				// 滚轮x坐标
	lv_coord_t pos_y;				// 滚轮y坐标
	const char * options;			// 滚轮选项内容
	uint8_t nowSelect;				// 当前选共享
	uint8_t *data;					// 滚轮控制的变量
}Roller_t;
static Label_t taUser_label[7];             // 标签
static Roller_t taUser_roller[6];			 // 滚轮
static lv_obj_t* slider;                     // 背光滑块slider_label
static lv_obj_t* slider_label;
static lv_obj_t* lv_msgbox;			// 修改时间弹窗
static lv_obj_t* timeConfigBtn;		// 时间配置按钮
static lv_obj_t* startBtn;			// 锁屏开启按钮
static lv_obj_t* closeBtn;		    // 锁屏关闭按钮
static lv_obj_t* dropdown;			// 锁屏时间下拉框
static uint8_t now_month;			// 当前月份
static uint8_t last_month;			// 上一次月份
static lv_timer_t* timer_refresh_rollor;
static const char* year_options = "2000\n2001\n2002\n2003\n2004\n2005\n2006\n2007\n"
		"2008\n2009\n2010\n2011\n2012\n2013\n2014\n2015\n2016\n2017\n2018\n2019\n2020\n"
		"2021\n2022\n2023\n2024\n2025\n2026\n2027\n2028\n2029\n2030\n2031\n2032\n2033\n"
		"2034\n2035\n2036\n2037\n2038\n2039\n2040\n2041\n2042\n2043\n2044\n2045\n2046\n"
        "2047\n2048\n2049\n2050";
static const char* month_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12";
static const char* day_options1 = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n"
		"14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30";
static const char* day_options2 = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n"
		"14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31";
static const char* day_options3 = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n"
		"14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28";
static const char* hour_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n"
		"14\n15\n16\n17\n18\n19\n20\n21\n22\n23";
static const char* min_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n"
		"14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33"
		"\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53"
		"\n54\n55\n56\n57\n58\n59";
static const char* sec_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n"
		"14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33"
		"\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53"
		"\n54\n55\n56\n57\n58\n59";

static void drop_event_cb(lv_event_t* e)
{
	uint16_t numID;
	lv_obj_t *target = lv_event_get_current_target(e);                 /* 获取当前触发源 */
	if (target == dropdown)
	{
		numID = lv_dropdown_get_selected(dropdown);
		switch(numID)
		{
		case 0:
			DA.breathTime = 0;  // 30S
			break;
		case 1:
			DA.breathTime = 30; // 60S
			break;
		case 2:
			DA.breathTime = 270; // 5min
			break;
		case 3:
			DA.breathTime = 570; // 10min
			break;
		case 4:
			DA.breathTime = 1770; // 10min
			break;
		default:
			break;
		}
		if (g_RW_State == RW_READY)
		{
		    g_RW_State = RW_WRITE_NAND_SCREEN;
		}
	}
}
static uint8_t get_now_select(uint16_t time)
{
	uint8_t select = 0;
	switch(time)
	{
	case 0:
		select = 0;
		break;
	case 30:
		select = 1;
		break;
	case 270:
		select = 2;
		break;
	case 570:
		select = 3;
		break;
	case 1770:
		select = 4;
		break;
	default:
		break;
	}
	return select;
}
static void msgbox_event_cb(lv_event_t* e)
{
    lv_obj_t *target = lv_event_get_current_target(e);                 /* 获取当前触发源 */

    if(lv_msgbox_get_active_btn(target) == 2)                          /* 获取按钮索引 */
    {
    	rtc_setDataTime(&SST.clockSetTime);
    	lv_obj_del(lv_msgbox);
    }
    else if (lv_msgbox_get_active_btn(target) == 3)
    {
    	lv_obj_del(lv_msgbox);
    }

}
/**
  * @brief	弹窗创建函数
  * @param  e 触发源
  * @retval None
  */
static void mxgbox_create(void)
{
	static const char* btns[5];
	btns[0] = " ";
	btns[1] = " ";
	btns[2] = dispText[DA.typeLanguage].ok;
	btns[3] = dispText[DA.typeLanguage].abolish;
	btns[4] = "";
	/* 消息框整体 */
	lv_msgbox = lv_msgbox_create(lv_scr_act(), dispText[DA.typeLanguage].timeConfig, \
			dispText[DA.typeLanguage].timeCont, btns, true);
	lv_obj_center(lv_msgbox);
	lv_obj_set_size(lv_msgbox, lv_pct(50), lv_pct(55));  //设置父对象的大小
    lv_obj_set_style_border_width(lv_msgbox, 0, LV_STATE_DEFAULT);                              /* 去除边框 */
    lv_obj_set_style_shadow_width(lv_msgbox, 20, LV_STATE_DEFAULT);                             /* 设置阴影宽度 */
    lv_obj_set_style_shadow_color(lv_msgbox, lv_color_hex(0xa9a9a9), LV_STATE_DEFAULT);         /* 设置阴影颜色 */
    lv_obj_set_style_pad_top(lv_msgbox,18,LV_STATE_DEFAULT);                                    /* 设置顶部填充 */
    lv_obj_set_style_pad_left(lv_msgbox,20,LV_STATE_DEFAULT);
    lv_obj_add_event_cb(lv_msgbox, msgbox_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
    /* 消息框标题 */
    lv_obj_t *title = lv_msgbox_get_title(lv_msgbox);                                           /* 获取标题部分 */            /* 设置字体 */
    lv_obj_set_style_text_color(title, lv_color_hex(0xff0000),LV_STATE_DEFAULT);
    /* 消息框主体 */
    lv_obj_t *content = lv_msgbox_get_content(lv_msgbox);    /* 获取主体部分 */
    lv_obj_set_height(content, lv_pct(35));        /* 设置字体 */
    lv_obj_set_style_text_color(content, lv_color_hex(0x6c6c6c), LV_STATE_DEFAULT);          /* 设置文本颜色：灰色 */
    lv_obj_set_style_pad_top(content,5,LV_STATE_DEFAULT);

    /* 消息框按钮 */
    lv_obj_t *btn = lv_msgbox_get_btns(lv_msgbox);                                           /* 获取按钮矩阵部分 */
    lv_obj_set_style_bg_opa(btn, 0, LV_PART_ITEMS);                                          /* 设置按钮背景透明度 */
    lv_obj_set_style_shadow_width(btn, 0, LV_PART_ITEMS);  				/* 去除按钮阴影 */
    lv_obj_set_style_pad_top(btn, 15, LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(btn, 5, LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(btn, lv_color_hex(0x2271df),LV_PART_ITEMS);                  /* 设置文本颜色（未按下）：蓝色 */
    lv_obj_set_style_text_color(btn, lv_color_hex(0xff0000),LV_PART_ITEMS|LV_STATE_PRESSED); /* 设置文本颜色（已按下）：红色 */
}
/**
  * @brief	按键事件回调函数
  * @param  parent:父对象
  * @retval None
  */
static void btn_event_cb(lv_event_t * e)
{
	lv_event_code_t code = lv_event_get_code(e);	// 获取触发条件
	lv_obj_t *target = lv_event_get_current_target(e);                 /* 获取当前触发源 */
	if (code == LV_EVENT_CLICKED)
	{
		if (target == timeConfigBtn)
		{
			/* 特殊事件回调 */
			mxgbox_create();
		}
		else if (target == startBtn)
		{
			DA.breathPlate = 1;

	    	lv_obj_add_state(startBtn, LV_STATE_CHECKED);
	    	lv_obj_clear_state(closeBtn, LV_STATE_CHECKED);
	    	lv_obj_clear_state(dropdown, LV_STATE_DISABLED);
		}
		else if (target == closeBtn)
		{
			DA.breathPlate = 0;
	    	lv_obj_add_state(closeBtn, LV_STATE_CHECKED);
	    	lv_obj_clear_state(startBtn, LV_STATE_CHECKED);
	    	lv_obj_add_state(dropdown, LV_STATE_DISABLED);
		}
		if (g_RW_State == RW_READY)
		{
		    g_RW_State = RW_WRITE_NAND_SCREEN;
		}
	}
}
/**
  * @brief	滑快事件回调函数
  * @param  e 触发源
  * @retval None
  */
static void slider_event_cb(lv_event_t * e)
{
	lv_obj_t *target = lv_event_get_current_target(e);                 /* 获取当前触发源 */
    if (target == slider)
    {
    	DS.bringhtNess = lv_slider_get_value(slider);
    	lv_label_set_text_fmt(slider_label, "%d %%", DS.bringhtNess); /* 设置文本内容 */
    	lcd_BackLight_adjust(DS.bringhtNess);
    	/* 将背光数据存储到NAND中 */
    	if (g_RW_State == RW_READY)
    	{
    		g_RW_State = RW_WRITE_NAND_SCREEN;
    	}
    }
}
/**
  * @brief	刷新年月日时分秒状态
  * @param  parent:父对象
  * @retval None
  */
static void roller_refresh_cb(lv_timer_t* timer)
{
	LV_UNUSED(timer);
	/* 遍历所有的滚轮，对按键状态进行更新 */
	for(uint8_t i = 0; i < lv_obj_get_child_cnt(parentObj); i++)
	{
		lv_obj_t* child = lv_obj_get_child(parentObj, i);
		if(lv_obj_check_type(child, &lv_roller_class))
		{
			Roller_t * rollerInfo = (Roller_t *)lv_obj_get_user_data(child);
			if (rollerInfo->id == 2)
			{
				if (last_month != now_month)
				{
					last_month = now_month;
					if (now_month % 2 == 0)	// 28 30
					{
						if (now_month != 2)  // 30
						{
							lv_roller_set_options(child, day_options2, LV_ROLLER_MODE_NORMAL);
							lv_roller_set_selected(child, rollerInfo->nowSelect, LV_ANIM_OFF);
						}
						else		// 28
						{
							lv_roller_set_options(child, day_options3, LV_ROLLER_MODE_NORMAL);
							lv_roller_set_selected(child, rollerInfo->nowSelect, LV_ANIM_OFF);
						}
					}
					else
					{
						lv_roller_set_options(child, day_options1, LV_ROLLER_MODE_NORMAL);
						lv_roller_set_selected(child, rollerInfo->nowSelect, LV_ANIM_OFF);
					}
				}

			}
		}
	}
}
/**
  * @brief	滚轮事件回调函数
  * @param  parent:父对象
  * @retval None
  */
static void roller_event_cb(lv_event_t * e)
{
	lv_obj_t * obj = lv_event_get_target(e);		// 获取触发源
	lv_event_code_t code = lv_event_get_code(e);	// 获取触发条件
	Roller_t * rollerInfo = (Roller_t *)lv_obj_get_user_data(obj);
	if (code == LV_EVENT_VALUE_CHANGED)
	{
		if (rollerInfo->id != 1 && rollerInfo->id != 2)  // 年、时、分、秒从0开始
		{
			*(rollerInfo->data) = (uint8_t)lv_roller_get_selected(obj);
		}
		else
		{												 // 月、日从1开始
			*(rollerInfo->data) = (uint8_t)lv_roller_get_selected(obj) + 1;
			if (rollerInfo->id == 1)
			{
				now_month = (uint8_t)lv_roller_get_selected(obj) + 1;
			}
		}
	}
}
/**
  * @brief	创建渐变蒙版
  * @param  cont: 标签父对象  rollorInfo:标签信息结构体
  * @retval None
  */
static void mask_event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target(e);

    static int16_t mask_top_id = -1;
    static int16_t mask_bottom_id = -1;

    if(code == LV_EVENT_COVER_CHECK) {
        lv_event_set_cover_res(e, LV_COVER_RES_MASKED);

    }
    else if(code == LV_EVENT_DRAW_MAIN_BEGIN) {
        /* add mask */
        const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
        lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
        lv_coord_t font_h = lv_font_get_line_height(font);

        lv_area_t roller_coords;
        lv_obj_get_coords(obj, &roller_coords);

        lv_area_t rect_area;
        rect_area.x1 = roller_coords.x1;
        rect_area.x2 = roller_coords.x2;
        rect_area.y1 = roller_coords.y1;
        rect_area.y2 = roller_coords.y1 + (lv_obj_get_height(obj) - font_h - line_space) / 2;

        lv_draw_mask_fade_param_t * fade_mask_top = lv_mem_buf_get(sizeof(lv_draw_mask_fade_param_t));
        lv_draw_mask_fade_init(fade_mask_top, &rect_area, LV_OPA_TRANSP, rect_area.y1, LV_OPA_COVER, rect_area.y2);
        mask_top_id = lv_draw_mask_add(fade_mask_top, NULL);

        rect_area.y1 = rect_area.y2 + font_h + line_space - 1;
        rect_area.y2 = roller_coords.y2;

        lv_draw_mask_fade_param_t * fade_mask_bottom = lv_mem_buf_get(sizeof(lv_draw_mask_fade_param_t));
        lv_draw_mask_fade_init(fade_mask_bottom, &rect_area, LV_OPA_COVER, rect_area.y1, LV_OPA_TRANSP, rect_area.y2);
        mask_bottom_id = lv_draw_mask_add(fade_mask_bottom, NULL);

    }
    else if(code == LV_EVENT_DRAW_POST_END) {
        lv_draw_mask_fade_param_t * fade_mask_top = lv_draw_mask_remove_id(mask_top_id);
        lv_draw_mask_fade_param_t * fade_mask_bottom = lv_draw_mask_remove_id(mask_bottom_id);
        lv_draw_mask_free_param(fade_mask_top);
        lv_draw_mask_free_param(fade_mask_bottom);
        lv_mem_buf_release(fade_mask_top);
        lv_mem_buf_release(fade_mask_bottom);
        mask_top_id = -1;
        mask_bottom_id = -1;
    }
}
/**
  * @brief	创建滚轮
  * @param  cont: 标签父对象  rollorInfo:标签信息结构体
  * @retval None
  */
static void rollor_create_by(lv_obj_t* cont, Roller_t * rollorInfo)
{
	lv_obj_t* roller = lv_roller_create(cont);
	lv_roller_set_visible_row_count(roller, rollorInfo->row_cnt);
	lv_obj_set_width(roller, rollorInfo->width);
	lv_roller_set_options(roller, rollorInfo->options, LV_ROLLER_MODE_NORMAL);
	lv_obj_align(roller, LV_ALIGN_TOP_LEFT, rollorInfo->pos_x, rollorInfo->pos_y);
	lv_roller_set_selected(roller, rollorInfo->nowSelect, LV_ANIM_OFF);
	lv_obj_set_user_data(roller, rollorInfo);
	lv_obj_set_style_text_color(roller, lv_color_white(), LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(roller, lv_color_black(), LV_PART_MAIN);
	lv_obj_set_style_bg_color(roller, lv_color_hex(0x3a96f1), LV_PART_SELECTED);
	lv_obj_set_style_bg_opa(roller, LV_OPA_50, LV_PART_SELECTED);
	lv_obj_set_style_border_opa(roller, LV_OPA_TRANSP, LV_STATE_DEFAULT); /* 完全透明 */
	lv_obj_add_event_cb(roller, roller_event_cb, LV_EVENT_VALUE_CHANGED, rollorInfo);
	lv_obj_add_event_cb(roller, mask_event_cb, LV_EVENT_ALL, NULL);
}
/**
  * @brief	初始化所有滚轮
  * @param  None
  * @retval None
  */
static void rollor_init(void)
{
	/* 初始化SST */
	SST.clockSetTime.year = DS.clockTime.year;
	SST.clockSetTime.month = DS.clockTime.month;
	SST.clockSetTime.day = DS.clockTime.day;
	SST.clockSetTime.hour = DS.clockTime.hour;
	SST.clockSetTime.min = DS.clockTime.min;
	SST.clockSetTime.sec = DS.clockTime.sec;
	taUser_roller[0].options = year_options;
	taUser_roller[0].data = &SST.clockSetTime.year;
	taUser_roller[0].nowSelect = DS.clockTime.year;
	taUser_roller[1].options = month_options;
	taUser_roller[1].data = &SST.clockSetTime.month;
	taUser_roller[1].nowSelect = DS.clockTime.month - 1;
	taUser_roller[2].options = day_options1;
	taUser_roller[2].data = &SST.clockSetTime.day;
	taUser_roller[2].nowSelect = DS.clockTime.day - 1;
	taUser_roller[3].options = hour_options;
	taUser_roller[3].data = &SST.clockSetTime.hour;
	taUser_roller[3].nowSelect = DS.clockTime.hour;
	taUser_roller[4].options = min_options;
	taUser_roller[4].data = &SST.clockSetTime.min;
	taUser_roller[4].nowSelect = DS.clockTime.min;
	taUser_roller[5].options = sec_options;
	taUser_roller[5].data = &SST.clockSetTime.sec;
	taUser_roller[5].nowSelect = DS.clockTime.sec;
	for (uint8_t i = 0; i < 6; i++)
	{
		taUser_roller[i].id = i;
		taUser_roller[i].width = lv_pct(8);
		taUser_roller[i].pos_x = lv_pct(i*12 + 27);
		taUser_roller[i].pos_y = lv_pct(39);
		taUser_roller[i].row_cnt = 3;
	}
	taUser_roller[0].width = lv_pct(15);
	taUser_roller[0].pos_x = lv_pct(20);
}
/**
  * @brief	初始化所有显示标签
  * @param  None
  * @retval None
  */
static void label_init(void)
{
	taUser_label[0].label_cont = dispText[DA.typeLanguage].setLight;
	taUser_label[1].label_cont = dispText[DA.typeLanguage].autoLock;
	taUser_label[2].label_cont = dispText[DA.typeLanguage].sysTime;
	taUser_label[3].label_cont = "-";
	taUser_label[4].label_cont = "-";
	taUser_label[5].label_cont = ":";
	taUser_label[6].label_cont = ":";

	for (uint8_t i = 0; i < 3; i++)
	{
		taUser_label[i].width = lv_pct(30);
		taUser_label[i].height = lv_pct(15);
		taUser_label[i].pos_x = lv_pct(3);
	}
	taUser_label[0].pos_y = lv_pct(7);
	taUser_label[1].pos_y = lv_pct(25);
	taUser_label[2].pos_y = lv_pct(55);

	for (uint8_t i = 0; i < 4; i++)
	{
		taUser_label[3+i].width = lv_pct(10);
		taUser_label[3+i].height = lv_pct(15);
		taUser_label[3+i].pos_y = lv_pct(54);
	}
	taUser_label[3].pos_x = lv_pct(36);
	taUser_label[3].pos_y = lv_pct(55);
	taUser_label[4].pos_x = lv_pct(48);
	taUser_label[4].pos_y = lv_pct(55);
	taUser_label[5].pos_x = lv_pct(73);
	taUser_label[6].pos_x = lv_pct(84);

}
/**
  * @brief	创建标签
  * @param  cont: 标签父对象  labInfo:标签信息结构体
  * @retval None
  */
static void label_create_by(lv_obj_t* cont, Label_t * labInfo)
{
	lv_obj_t* label = lv_label_create(cont);
	lv_label_set_text(label, labInfo->label_cont);
	lv_obj_set_style_text_color(label, lv_color_white(), LV_STATE_DEFAULT);  // 设置标签字体颜色
    lv_obj_set_style_width(label, labInfo->width, LV_STATE_DEFAULT);
    lv_obj_set_style_height(label, labInfo->height, LV_STATE_DEFAULT);
    lv_obj_align(label, LV_ALIGN_TOP_LEFT, labInfo->pos_x, labInfo->pos_y);
    lv_obj_set_user_data(label, labInfo);
}

void UI_create_communication(void)
{
    /* 按钮初始化 */
//    btn_init();
    /* 标签初始化 */
    label_init();
    /* 滚动条初始化 */
    rollor_init();
	parentObj_img = lv_img_create(lv_scr_act());
    lv_img_set_src(parentObj_img, &dsc_img_buff[2]);
    lv_obj_add_style(parentObj_img, &style_parentObj, LV_STATE_DEFAULT);  //添加父对象为无填充样式
    lv_obj_set_size(parentObj_img, lv_pct(100), lv_pct(100));  //设置父对象的大小
    lv_obj_align(parentObj_img, LV_ALIGN_BOTTOM_MID, 0, 0);  //设置父对象的位置
    /* 功能设置界面父对象 */
    parentObj = lv_obj_create(lv_scr_act());  //创建父对象
    lv_obj_add_style(parentObj, &style_parentObj, LV_STATE_DEFAULT);
    lv_obj_set_size(parentObj, LV_PCT(100), LV_PCT(83));  //设置父对象的大小
    lv_obj_set_style_bg_color(parentObj,lv_palette_main(LV_PALETTE_GREEN),LV_STATE_DEFAULT);
    lv_obj_align(parentObj, LV_ALIGN_BOTTOM_LEFT, 0, 0);  //设置父对象的位置

    timeConfigBtn= lv_btn_create(parentObj);
    lv_obj_add_style(timeConfigBtn, &style_btn4, LV_STATE_DEFAULT);
    lv_obj_align(timeConfigBtn,LV_ALIGN_TOP_LEFT, lv_pct(45), lv_pct(85));
    lv_obj_t * lable = lv_label_create(timeConfigBtn);
    lv_label_set_text(lable, dispText[DA.typeLanguage].setSystemTime);
    lv_obj_align_to(lable, timeConfigBtn, LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_style_bg_color(timeConfigBtn, lv_color_hex(0x3a96f1), LV_STATE_CHECKED);
    lv_obj_add_event_cb(timeConfigBtn, btn_event_cb, LV_EVENT_CLICKED, NULL);
    /* 创建按钮 */

	startBtn= lv_btn_create(parentObj);
    lv_obj_add_style(startBtn, &style_btn4, LV_STATE_DEFAULT);
    lv_obj_align(startBtn,LV_ALIGN_TOP_LEFT, lv_pct(25), lv_pct(22));
    lable = lv_label_create(startBtn);
    lv_label_set_text(lable, dispText[DA.typeLanguage].on);
    lv_obj_align(lable,LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_size(startBtn, lv_pct(15), lv_pct(13));
    lv_obj_set_style_bg_color(startBtn, lv_color_hex(0x3a96f1), LV_STATE_CHECKED);
    lv_obj_add_event_cb(startBtn, btn_event_cb, LV_EVENT_CLICKED, NULL);

	closeBtn= lv_btn_create(parentObj);
    lv_obj_add_style(closeBtn, &style_btn4, LV_STATE_DEFAULT);
    lv_obj_align(closeBtn,LV_ALIGN_TOP_LEFT, lv_pct(45), lv_pct(22));
    lable = lv_label_create(closeBtn);
    lv_label_set_text(lable, dispText[DA.typeLanguage].off);
    lv_obj_align(lable,LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_size(closeBtn, lv_pct(15), lv_pct(13));
    lv_obj_set_style_bg_color(closeBtn, lv_color_hex(0x3a96f1), LV_STATE_CHECKED);
    lv_obj_add_event_cb(closeBtn, btn_event_cb, LV_EVENT_CLICKED, NULL);
	/* 创建下拉选项 */

	dropdown = lv_dropdown_create(parentObj);
	lv_dropdown_set_options(dropdown, dispText[DA.typeLanguage].lockTimeOption);
	lv_dropdown_set_selected(dropdown, get_now_select(DA.breathTime));
	lv_obj_set_width(dropdown, lv_pct(20));
	lv_obj_align(dropdown, LV_ALIGN_TOP_LEFT, lv_pct(70), lv_pct(20));
	lv_dropdown_set_selected_highlight(dropdown, false);
	lv_obj_set_style_bg_color(dropdown, lv_color_hex(0x292929), LV_PART_ITEMS | LV_STATE_CHECKED);
	lv_obj_set_style_bg_opa(dropdown, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
	lv_obj_add_event_cb(dropdown, drop_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
    /* 创建静态标签 */
    for (uint8_t i = 0; i < 7; i++)
    {
    	label_create_by(parentObj, &taUser_label[i]);
    }
    /* 背光调节 */
    slider = lv_slider_create(parentObj);                  /* 创建滑块 */
    lv_obj_set_size(slider, lv_pct(55), lv_pct(5));        /* 设置大小 */
    lv_obj_align(slider, LV_ALIGN_TOP_LEFT, lv_pct(25), lv_pct(10)); /* 设置位置 */
    lv_slider_set_value(slider, DS.bringhtNess, LV_ANIM_OFF);          /* 设置当前值 */
    lv_obj_set_style_bg_color(slider, lv_color_hex(COLOUR_WIIP_ORANGE), LV_PART_INDICATOR);
    lv_obj_set_style_bg_color(slider, lv_color_hex(COLOUR_WIIP_ORANGE), LV_PART_KNOB);
    lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);

    slider_label = lv_label_create(parentObj); /* 创建百分比标签 */
    lv_obj_set_style_text_color(slider_label, lv_color_white(), LV_STATE_DEFAULT);  // 设置标签字体颜色
    lv_obj_set_width(slider_label, lv_pct(15));
    lv_label_set_text_fmt(slider_label, "%d %%", DS.bringhtNess); /* 设置文本内容 */
    lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0); /* 设置位置 */
    /* 创建滚动条 */
    for (uint8_t i = 0; i < 6; i++)
    {
    	rollor_create_by(parentObj, &taUser_roller[i]);
    }
    /* 刷新按钮状态 */
    if (DA.breathPlate == 0)
    {
    	lv_obj_add_state(closeBtn, LV_STATE_CHECKED);
    	lv_obj_add_state(dropdown, LV_STATE_DISABLED);
    	lv_obj_clear_state(startBtn, LV_STATE_CHECKED);
    }
    else
    {
    	lv_obj_add_state(startBtn, LV_STATE_CHECKED);
    	lv_obj_clear_state(closeBtn, LV_STATE_CHECKED);
    }
    /* 启动定时器用于刷新数据 */
    timer_refresh_rollor = lv_timer_create(roller_refresh_cb, 200, NULL);		// 定时刷新
}
void UI_delete_communication(void)
{
	lv_obj_del(parentObj);
	lv_obj_del(parentObj_img);
	lv_timer_del(timer_refresh_rollor);
}


